<?php
/**
 * Created by PhpStorm.
 * User: gaochaolyf
 * Date: 16/5/19
 * Time: 上午11:43
 */

namespace api\Model;

use Think\Model;

class CustCodeModel extends Model
{
    function __construct() {
        $this->model = M('CustCode');
    }

    public function getCustCode($field = array('*'), $condition = array()) {
        $data = $this->model->where($condition)->field($field)->find();
        //$data = $data ? $data : array();
        return $data;
    }

    public function updateCustCode($mobile = 0, $code = '') {
        $affected = $this->model->where(array('mobile' => $mobile))->setField(array('code' => $code, 'update_at' => time()));
        return $affected;
    }

    public function addCustCode($mobile = 0, $code = '') {
        $insert_id = $this->model->data(array(
            'code'      => $code,
            'mobile'    => $mobile,
            'add_at'    => time(),
            'update_at' => time()
        ))->add();
        return $insert_id;
    }

    public function getCustCodeCount($mobile = 0) {
        $count = $this->model->where(array('mobile' => $mobile))->count();
        return $count;
    }
    

}